package com.zjk.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjk.pojo.dto.ProductDTO;
import com.zjk.pojo.product.SearchItem;
import com.zjk.pojo.product.TbDict;
import com.zjk.pojo.product.TbProduct;
import com.zjk.product.service.ProductService;
import com.zjk.result.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: gfk
 * @create: 2022/11/1
 * @Description:
 * @FileName: ProductController
 * @History:
 * @自定义内容：
 */
@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping("save")
    public ResultResponse save(@RequestBody ProductDTO productDTO){
        String name = productDTO.getName();
        if (name==null){
            return new ResultResponse(false,"名字不能为空");
        }
        Integer minMoney = productDTO.getMinMoney();
        Integer maxMoney = productDTO.getMaxMoney();
        if (maxMoney<minMoney){
            return new ResultResponse(false,"最大金额不能小于最小金额");
        }
        return  productService.save(productDTO);
    }

        @GetMapping("productTypeList")
    public List<TbDict> getProductTypeList(){
        return productService.getProductTypeList();
    }

    @GetMapping("repaymentWayList")
    public List<TbDict> getRepaymentWayList(){
        return productService.getRepaymentWayList();
    }
    @PostMapping("/saveProductType")
    public ResultResponse saveProductType(@RequestBody TbDict tbDict){
        return productService.saveProductType(tbDict);
    }

    @PostMapping("findPage/{pageNo}/{pageSize}")
    public Page<TbProduct> list(@PathVariable Integer pageNo,
                                @PathVariable Integer pageSize){
        return productService.list(pageNo,pageSize);
    }

     @GetMapping("submit/{id}")
    public ResultResponse submit(@PathVariable Integer id){
        return productService.submit(id);
    }

    @GetMapping("cfoAudit/{id}/{ok}")
    public ResultResponse cfoAudit(@PathVariable Integer id,@PathVariable boolean ok){
        return productService.cfoAudit(id,ok);
    }

        @GetMapping("ceoAudit/{id}/{ok}")
        public ResultResponse ceoAudit(@PathVariable Integer id,@PathVariable boolean ok){
            return productService.ceoAudit(id,ok);
        }
    @PostMapping("findSearchItem")
    public List<SearchItem>  findSearchItem(@RequestBody Map searchMap){

        return  productService.findSearchItem(searchMap);
    }
}
